home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 147_01 / logon.c < prev    next >
Text File  |  1985-03-09  |  13KB  |  491 lines

  1. /****************************************************************
  2. * LOGON.C
  3.  
  4. Release 7: RBBS 4.1 Edit 02 - Changed getname calls to add prompts.
  5. Release 6: RBBS 4.1 Edit 01 - if RBBS P used, keeps original logtime.
  6.                  - also added <cr> to LASTCALR file.
  7. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  8.                 - Activated lstmsg for 1st 7 non-PERSONALs
  9.                 - Inserted NOSITE into newuser
  10.                 - Inserted PERSONLY in closing
  11.                 - Fixed duplicate user entry problem
  12.                   by closing and reopening USERS.CCC
  13.                   in newuser - now immune to lost carrier
  14.                   which caused the problem!
  15. Release 4: RBBS 4.0 Edit 21 - changed sysop flag to "!" in logon
  16.                 - forced-truncated names in getlast
  17.                 - added bias in loguser
  18. Release 3: RBBS 4.0 Edit 20 - fixed LASTREAD bug in getlast
  19. Release 1: RBBS 4.0 Edit 18
  20.  
  21. * This file contains the functions:
  22.  
  23. * logon        calls getname, checkuser, testpwd, updtuser, and
  24.                 maybe newuser ... in general, logs the user into
  25.                 the program and validates the user.
  26.  
  27. * checkuser    checks the entry in USERS.CCC
  28.  
  29. * chkpwd    prompts for a new password
  30.  
  31. * testpwd    prompts user for login password and checks it
  32.  
  33. * newuser    registers a new user
  34.  
  35. * updtuser    updates the current user entry in USERS.CCC
  36.  
  37. * loguser    makes an entry in CALLERS.CCC
  38.  
  39. * lstuser    sysop only - lists CALLERS.CCC in reverse order
  40.  
  41. * welcome    calls bufinmsg to display WELCOME.CCC
  42.  
  43. * closing    closes session.  Called by gocpm and goodbye.
  44.                 Warns if only PERSONAL examined, offers others,
  45.                 and offers to leave msg for sysop.  Closes .MSG
  46.                 and USERS.CCC
  47.  
  48. ****************************************************************/
  49. #include    <bdscio.h>
  50. #include    "rbbs4.h"
  51.  
  52. /****************************************************************/
  53. logon(fd,u)        /* Logon gets the callers name        */
  54.             /* pwd and checks the users file    */
  55.             /* If the user is a new user, it gets    */
  56.             /* add'l info & adds to the user file.    */
  57.             /* It sets the user struct.        */
  58. int    fd;
  59. struct    _user    *u;
  60. {
  61.     int    valid_user, i;
  62.     int    *p;
  63.     char    name[NAMELGTH+1];
  64.  
  65.     valid_user = FALSE;
  66.     i = 0;
  67.     p = 0x59;
  68. #if    DATETIME
  69.     get_date();
  70.     strcpy(logdate,sysdate);
  71. #endif
  72.     do
  73.     {
  74.         u->recno = 0;
  75. #if    LASTREAD
  76.         rtnok = getlast(u,fd,name);
  77. #endif
  78.         if (!rtnok)
  79.             while ( (getname(name,"Enter your name: ")) )
  80.                 crlf(1);
  81.         else
  82.             u->recno = *p;
  83.         if (checkuser(fd,name,u,u->recno))
  84.         {
  85.             if (*(u->ustat) == '#')
  86.             {
  87.                 bufinmsg("TWITMSG");
  88.                 hexit();
  89.             }
  90.             belflg = u->bellflag;
  91.             expert = u->xpert;
  92.             if (!rtnok)
  93.                 testpwd(u);
  94.             if ( (!strcmp(u->nm,"SYSOP")) || (*(u->ustat) == '!'))
  95.                 sysop = TRUE;
  96.             sprintf(tmpstr,"Hello again, %s!!",u->nm);
  97.             outstr(tmpstr,2);
  98.             sprintf(tmpstr,"Last logon: %s",u->lastlog);
  99.             outstr(tmpstr,1);
  100.             sprintf(tmpstr,"This logon: %s",logdate);
  101.             outstr(tmpstr,1);
  102.             strcpy(u->lastlog,logdate);
  103.             if (!rtnok)
  104.                 strcpy(u->lastlog,logdate);
  105.             else
  106.                 strcpy(logdate,u->lastlog);
  107.             updtuser(u,fd);
  108.             valid_user = TRUE;
  109.         }
  110.         else
  111.         {
  112. #if    !PREREG
  113.             valid_user = newuser(u,name,fd);
  114. #endif
  115.             if (++i > 2)
  116.                 flushcaller();
  117.             else
  118.                 crlf(1);
  119.         }
  120.     } while (!valid_user);
  121. }
  122. /****************************************************************/
  123. checkuser(fd,name,u,n)        /*Checks the user file & exits */
  124. int    fd,n;            /* TRUE if a valid user after    */
  125. char    *name;            /* loading a user structure    */
  126. struct    _user    *u;
  127. {
  128.     int    ndx,m;
  129.  
  130.     formrec(tmpstr,SECSIZ);
  131.     readrec(fd,0,tmpstr,1);
  132.     sscanf(tmpstr,"MAX REC: %d",&u->maxno);
  133.     if ( !(m = n) )
  134.         ++m;
  135.     for (ndx = m; ndx <= u->maxno; ndx++)
  136.     {
  137.         formrec(tmpstr,SECSIZ);
  138.         readrec(fd,ndx,tmpstr,1);
  139.         sscanf(tmpstr+NM,"%s",u->nm);            /* NM:    */
  140.         capstr(u->nm);
  141.         if( n || !strcmp(name,u->nm) )
  142.         {
  143.             u->recno = ndx;
  144.             sscanf(tmpstr+PRV,"%s",u->ustat);    /* PRV:    */
  145.             sscanf(tmpstr+UBL,"%d",&u->bellflag);    /* UBL:    */
  146.             sscanf(tmpstr+UXP,"%d",&u->xpert);    /* UXP:    */
  147.             sscanf(tmpstr+PWD,"%s",u->pwd);        /* PWD:    */
  148.             sscanf(tmpstr+LLG,"%s",u->lastlog);    /* LLG:    */
  149.             sscanf(tmpstr+FRM,"%s",u->from);    /* FRM:    */
  150.             sscanf(tmpstr+LMG0,"%d",&u->lstmsg[0]);    /* LMG0:*/
  151.             sscanf(tmpstr+LMG1,"%d",&u->lstmsg[1]);    /* LMG1:*/
  152.             sscanf(tmpstr+LMG2,"%d",&u->lstmsg[2]);    /* LMG2:*/
  153.             sscanf(tmpstr+LMG3,"%d",&u->lstmsg[3]);    /* LMG3:*/
  154.             sscanf(tmpstr+LMG4,"%d",&u->lstmsg[4]);    /* LMG4:*/
  155.             sscanf(tmpstr+LMG5,"%d",&u->lstmsg[5]);    /* LMG5:*/
  156.             sscanf(tmpstr+LMG6,"%d",&u->lstmsg[6]);    /* LMG6:*/
  157.             return TRUE;
  158.         }
  159.     }
  160.     return FALSE;
  161. }
  162. /****************************************************************/
  163. chkpwd(n)        /* Gets a new password and returns it    */
  164. char    *n;
  165. {
  166.     int    flag;
  167.     char    check[7];
  168.  
  169. #if    PWCASE
  170.     outstr("WARNING: Case of password characters is significant!",2);
  171. #endif
  172.     do
  173.     {
  174.         outstr("Enter new password <6 chars>:  ",4);
  175.         do
  176.         {
  177.             cflg = 2;
  178.             instr("",n,6);
  179.         } while (!*n);
  180.         outstr("Enter the new password again:  ",3);
  181.         do
  182.         {
  183.             cflg = 2;
  184.             instr("",check,6);
  185.         } while (!*check);
  186. #if    !PWCASE
  187.         upstr(n);
  188.         upstr(check);
  189. #endif
  190.         if (flag = strcmp(n,check))
  191.             outstr("No match.  Try again.",3);
  192.         crlf(1);
  193.     } while (flag);
  194. }
  195. /****************************************************************/
  196. testpwd(u)        /* Permits up to 3 tries at entering     */
  197. struct    _user    *u;    /* password, then exits            */
  198. {
  199.     int    i;
  200.     char    input[7];
  201.  
  202.     setmem(sav,SECSIZ,0);
  203.     for ( i = 0; i < 3; i++)
  204.     {
  205.         outstr("Password:  ",4);
  206.         cflg = 2;
  207.         instr("",input,6);
  208. #if    !PWCASE
  209.         upstr(input);
  210. #endif
  211.         if (!strcmp(input,u->pwd))
  212.         {
  213.             outstr(" [OK]",1);
  214.             return;
  215.         }
  216.         sprintf(tmpstr," WRONG!, %d tr%s left",2-i,(i==1)?"y":"ies");
  217.         outstr(tmpstr,0);
  218.     }
  219.     flushcaller();
  220. }
  221. /****************************************************************/
  222. flushcaller()
  223. {
  224.     crlf(1);
  225.     outstr("SORRY, TOO MANY FAILURES!  GOODBYE",2);
  226.     hexit();    /* Hangup    */
  227. }
  228. /****************************************************************/
  229. #if    !PREREG
  230. newuser(u,name,fd)        /*DOUBLE CHECKS NEW USER & GETS    */
  231. struct    _user    *u;        /*INFO TO ADD NEW USER. ADDS    */
  232. char    *name;            /*NEW USER TO FILE. DOES NOT    */
  233. int    fd;            /*CLOSE USER FILE        */
  234. {
  235.     int    userstatus;
  236.     int    correct;
  237.     char    place[SITELGTH];
  238.     char    passwd[7];
  239. #if    LOCKEM
  240.     char    temp[SECSIZ];
  241. #endif
  242.  
  243.     correct = FALSE;
  244. #if    !LASTREAD
  245.     sprintf(tmpstr,"!!WELCOME %s!!",name);
  246.     outstr(tmpstr,2);
  247.     crlf(1);
  248.     userstatus = getyn("Is the name correct");
  249.     if (!userstatus)
  250.         return(FALSE);    
  251. #endif
  252. #if    NOSITE && LASTREAD
  253.     strcpy(place," ");
  254. #else
  255.     do
  256.     {
  257.         sprintf(tmpstr,"Enter your %s: ",SITEPROMPT);
  258.         outstr(tmpstr,4);
  259.         instr("",place,SITELGTH);
  260.         capstr(place);
  261.         crlf(1);
  262.         sprintf(tmpstr,"Is the name, %s, correct",place);
  263.         correct = getyn(tmpstr);
  264.     }while(!correct);
  265. #endif
  266. #if    LASTREAD
  267.     strcpy(passwd,"123456");
  268. #else
  269.     chkpwd(passwd);
  270. #endif
  271.     welcome();
  272.  
  273.     formrec(tmpstr,SECSIZ);
  274.     sprintf(tmpstr+NM,"%s",name);        /* NM:    */
  275.     sprintf(tmpstr+PRV,"%c%c",NEWFLAG,0);    /* PRV:    */
  276.     sprintf(tmpstr+UBL,"%1d",belflg);    /* UBL:    */
  277.     sprintf(tmpstr+UXP,"%1d",expert);    /* UXP:    */
  278.     sprintf(tmpstr+PWD,"%s",passwd);    /* PWD:    */
  279.     sprintf(tmpstr+LLG,"%s",logdate);    /* LLG:    */
  280.     sprintf(tmpstr+FRM,"%s",place);        /* FRM:    */
  281.     sprintf(tmpstr+LMG0,"%03d",0);        /* LMG0:*/
  282.     sprintf(tmpstr+LMG1,"%03d",0);        /* LMG1:*/
  283.     sprintf(tmpstr+LMG2,"%03d",0);        /* LMG2:*/
  284.     sprintf(tmpstr+LMG3,"%03d",0);        /* LMG3:*/
  285.     sprintf(tmpstr+LMG4,"%03d",0);        /* LMG4:*/
  286.     sprintf(tmpstr+LMG5,"%03d",0);        /* LMG5:*/
  287.     sprintf(tmpstr+LMG6,"%03d",0);        /* LMG6:*/
  288. #if    LOCKEM
  289.     formrec(temp,SECSIZ);
  290.     if (lokrec(fd,-1))
  291.         ioerr("locking USERS.CCC");
  292.     readrec(fd,0,temp,1);
  293.     sscanf(temp,"MAX REC: %d",&u->maxno);
  294. #endif
  295.     Rriterec(fd,++u->maxno,1,tmpstr);
  296.  
  297.     formrec(tmpstr,SECSIZ);
  298.     sprintf(tmpstr,"MAX REC: %d",u->maxno);
  299.     Rriterec(fd,0,1,tmpstr);
  300. #if    LOCKEM
  301.     frerec(fd,-1);
  302. #endif
  303.     close(fd);
  304.     fd = openfile(DSK(USERS.CCC));
  305.     /* RELOAD THE CURRENT USER TO BE THE NEW USER */
  306.     checkuser(fd,name,u,u->maxno);
  307.     return (TRUE);
  308. }
  309. #endif
  310. /****************************************************************/
  311. updtuser(u,fd)
  312. stru